package com.dopios.services.webapp.utilities;

import com.dopios.services.persistance.domain.CityAdvice;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;


public class AdviceValidator implements Validator {

    @Override
    public boolean supports(Class<?> aClass) {
        return false;  //To change body of implemented methods use File | Settings | File Templates.
    }

    @Override
    public void validate(Object o, Errors errors) {
    if (o instanceof CityAdvice){
        CityAdvice advice = (CityAdvice)o;
        if(advice.getAdvice().trim().length()>255){
            errors.rejectValue("advice", "error.advice.length.exceeded.", "Advice cannot be more than 255 characters");
        }
        //Could validate against city in the DB or Users as well...
    }
    }
}
